
const fs = require('fs')
const moment = require('moment');

exports.infoHandler = (req,res,next)=>{
    fs.appendFile('./info.txt',`${req.method}--${req.url}--${moment().format('YYYY-MM-DD HH:mm:ss')}\r\n`,(err)=>{})
    next()
}

// 全局错误中间件  

exports.errorHandler = (err,req,res,next)=>{
    if(err === 3){
        res.send({
            code:3,
            message:'token验证失败'
        })
    }

    if(err === 4){
        res.send({
            code:4,
            message:'参数数量不对'
        })
    }

    if(err === 5){
        res.send({
            code:5,
            message:'参数格式不对'
        })
    }
}